build-client:
	@echo make sure trunk in PATH variable
	#cd client; trunk serve; cd ..
	cargo r --bin client

build-server:
	#cd server; cargo r; cd ..
	cargo r --bin server

format-code:
	cargo fmt

rust-version:
	rustc --version
	@echo you should use rustc version 1.68.1 nightly, see rust.version
	# rustup default nightly-2023-01-10

show-rust-targets:
	rustup show
	@echo show result in file rust.version

rust-add-target-wasm32-deps:
	rustup target add wasm32-unknown-unknown

download-trunk-deps:
	# since rustc version is 1.68.0 nightly, can not build from source
	# cargo install trunk
	# mirrored download, remove prefix ghproxy.cc
	wget https://ghproxy.cc/https://github.com/trunk-rs/trunk/releases/download/v0.20.3/trunk-x86_64-unknown-linux-gnu.tar.gz

podman-pull-postgresql:
	podman pull m.daocloud.io/docker.io/library/postgres:alpine 

podman-postgres-run-with-init:
	podman volume create postgres-volume
	podman run -d --name=postgres-alpine -p 5432:5432 -v postgres-volume:/var/lib/postgres/data -e POSTGRES_PASSWORD=123456 postgres:alpine
	@echo "Your podman posgresql password is: 123456, user is: posgres"

check-podman-up-posgres:
	podman ps

jump-into-podman-posgres:
	podman exec -it postgres-alpine psql -U postgres # in postgres shell

host-ping-podman-posgresql:
	ifconfig # check docker field ip
	#ping 172.17.0.1:5432

bash-set-database-url:
	bash; export DATABASE_URL=postgres://postgres:123456@172.17.0.1:5432/blog-backend-db;
	@echo then run server: cargo run --bin server

download-dbgate-and-exec-it:
	# mirrored download, remove ghproxy.cc prefix
	wget -O /tmp/dbgate.AppImage https://ghproxy.cc/https://github.com/dbgate/dbgate/releases/download/v5.5.3/dbgate-5.5.3-linux_x86_64.AppImage
	chmod +x /tmp/dbgate.AppImage
	/tmp/dbgate.AppImage &
	@echo 'now new a db and comsume this project .sql file, see sqls_data_file/postgres_create_db_and_table.sql'
	
check-server-port-running:
	sudo lsof -i tcp:12345

notes:
	@echo this is for config or build stuff
	@echo [one] setup env for develop
	@echo 'see makefile target: rust-version | rust-add-target-wasm32-deps | download-trunk-deps | podman-pull-postgresql | podman-postgres-run-with-init'
	@echo 'use dbgate to manage podman container postgres database, see makefile target: download-dbgate-and-exec-it'
	@echo 'setup db and tables now, then set your DATABASE_URL env like export in bash'
	@echo [two] up server side
	@echo 'see makefile target: build-server | check-server-port-running'
	@echo [three] up client side
	@echo 'see makefile target: build-client'
	@echo [four] browser open client side port at localhost, login with github account
	@echo [however] I can not login with my github account, because I was baned
